package com.cnzhy;

import com.cnzhy.config.NettyConfig;
import com.cnzhy.server.WebSocketNettyServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * netty服务端启动
 *
 * @author zhaoyan5
 */
@SpringBootApplication
public class ServerSpringBootApplication implements CommandLineRunner {

    private final WebSocketNettyServer webSocketNettyServer;

    private final NettyConfig nettyConfig;

    @Autowired
    public ServerSpringBootApplication(WebSocketNettyServer webSocketNettyServer, NettyConfig nettyConfig) {
        this.webSocketNettyServer = webSocketNettyServer;
        this.nettyConfig = nettyConfig;
    }

    @Override
    public void run(String... args) {
        new Thread(() -> webSocketNettyServer.start(nettyConfig.getPort())).start();
    }

    /**
     * 多人聊天室测试地址:http://localhost:8080/
     */
    public static void main(String[] args) {
        SpringApplication.run(ServerSpringBootApplication.class, args);
    }
}
